package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * author Link
 *
 * @version 1.0
 * @date 2025/4/3  22:00
 */
@RestController
@RequestMapping("/api/v1/article")
@Slf4j
public class ArticleHomeController {

    @Autowired
    private ApArticleService apArticleService;

    /**
     * 加载首页文章列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        log.info("加载首页文章列表:{}", dto);
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_MORE,dto);
    }

    /**
     * 加载更多
     *
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        log.info("加载更多:{}", dto);
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_MORE,dto);
    }

    /**
     * 加载最新
     *
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        log.info("加载最新:{}", dto);
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_NEW,dto);
    }

    /**
     * 新增app端文章内容
     * @param articleDto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto articleDto){
        log.info("新增文章内容：{}",articleDto);
        return apArticleService.saveArticle(articleDto);
    }
}
